<?php
/**
 * 管理后台-权限管理控制器-RCenter
 * 用于控制权限管理页的显示、权限条目的增删改
 * @author Pony
 */
class right extends spController{
	function __construct(){
		if($_SESSION['ucid'] != RC_ADMIN){$this->error('您不是RCenter管理员',spUrl('main','login'));}
		parent::__construct();
	}
	
	function index(){
		$this -> group_options = spClass('m_group') -> exGroup();
		$this -> rightlist = spClass('m_right') -> getRights();
		$this -> rightlist = spClass('m_group') -> exGroupId($this -> rightlist);
		$this -> tpl_img = TPL_IMG;
		$this -> display('admin_right.htm');
	}
	
	function add(){
		$r = spClass('m_right') -> addRight($this -> spArgs('rightsnum'),
							 				  $this -> spArgs('description',' '),
											  $this -> spArgs('groupid'),
											  $this -> spArgs('allow'),
											  $this -> spArgs('begin'),
											  $this -> spArgs('end'));
		if($r > 0) $this->success('成功创建一条权限',spUrl('right'));
		else $this -> error('创建权限失败',spUrl('right'));
	}
	
	function delete(){
		$deletes_wait = $this->spArgs('delete');
		while ($foo = each($deletes_wait)){
			spClass('m_right') -> deleteRight($foo['value']);
		}
		$this->success('已从RCenter中删除选定权限',spUrl('right'));
	}
	
	function edit_page(){
		$this -> rightinfo = spClass('m_right') -> getRights($this->spArgs('rightid'));
		$this -> timebegin = empty($this -> rightinfo['begin']) ? 0 : date('YmdHis',$this -> rightinfo['begin']);
		$this -> timeend = empty($this -> rightinfo['end']) ? 0 : date('YmdHis',$this -> rightinfo['end']);
		$this -> group_options = spClass('m_group') -> exGroup();
		$this -> tpl_img = TPL_IMG;
		$this -> display('admin_right_edit.htm');
	}
	
	function edit(){
		$r = spClass('m_right') -> editRight($this -> spArgs('rightid'),
											  $this -> spArgs('rightsnum'),
											  $this -> spArgs('description',' '),
											  $this -> spArgs('groupid'),
											  $this -> spArgs('allow'),
											  $this -> spArgs('begin'),
											  $this -> spArgs('end'));
		if($r > 0) $this->success('成功修改一条权限',spUrl('right'));
		else $this -> error('修改权限失败或无变化',spUrl('right'));
	}
}